home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / src / RNG.h < prev    next >
C/C++ Source or Header  |  1994-08-12  |  2KB  |  59 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /* 
  3. Copyright (C) 1988 Free Software Foundation
  4.     written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  5.  
  6. This file is part of the GNU C++ Library.  This library is free
  7. software; you can redistribute it and/or modify it under the terms of
  8. the GNU Library General Public License as published by the Free
  9. Software Foundation; either version 2 of the License, or (at your
  10. option) any later version.  This library is distributed in the hope
  11. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  12. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. PURPOSE.  See the GNU Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with this library; if not, write to the Free Software
  16. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #ifndef _RNG_h
  19. #define _RNG_h 1
  20. #ifdef __GNUG__
  21. #pragma interface
  22. #endif
  23.  
  24. #include <assert.h>
  25. #include <math.h>
  26. #include <_G_config.h>
  27.  
  28. union PrivateRNGSingleType {               // used to access floats as unsigneds
  29.     float s;
  30.     _G_uint32_t u;
  31. };
  32.  
  33. union PrivateRNGDoubleType {               // used to access doubles as unsigneds
  34.     double d;
  35.     _G_uint32_t u[2];
  36. };
  37.  
  38. //
  39. // Base class for Random Number Generators. See ACG and MLCG for instances.
  40. //
  41. class RNG {
  42.     static PrivateRNGSingleType singleMantissa;    // mantissa bit vector
  43.     static PrivateRNGDoubleType doubleMantissa;    // mantissa bit vector
  44. public:
  45.     RNG();
  46.     //
  47.     // Return a long-words word of random bits
  48.     //
  49.     virtual _G_uint32_t asLong() = 0;
  50.     virtual void reset() = 0;
  51.     //
  52.     // Return random bits converted to either a float or a double
  53.     //
  54.     float asFloat();
  55.     double asDouble();
  56. };
  57.  
  58. #endif
  59.